{layout name="public/layout" /}
{include file='yxnavbar'}
<style>
    .div_flex{
        display: flex !important;
    }
    .div_none{
        display: none; !important;
    }
    .shadow-box{
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background: rgba(0,0,0,0.5);
    }
    .alert_form {
        position: absolute;
        top: 10%;
        left: 30%;
        background: #fff;
        height: 80%;
        width: 40vw;
        max-height: 700px;
    }
    .shadow-box .panel-body{
        max-height: 88%;
        overflow-y: auto;
    }
    .shadow-box .panel .panel-heading .btn{
        padding-bottom: 2px;
        padding-top: 0px;
    }
</style>



<div class="main">
    {include file='../../plugin/coupon/template/web/common_nav'}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="coupon.flag" />
                <input type="hidden" name="coupon_id" value="{$coupon_id}" />

                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">优惠券名称</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $coupon_list_arr $row}
                            <a href="{php echo createWebUrlPlugin('coupon.flag',array('themeid'=>$themeid,'coupon_id'=>$row['id'],'status'=>$status));}"
                               class="btn {if $coupon_id == $row['id']}btn-primary{else}btn-default{/if}">
                                {$row['name']}
                                <span style="color: #ff0000">{$row['get_num']}/{$row['use_num']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                    {if count($themelist)>1 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
                {if $is_presale}
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">使用条件</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $used_type_arr $row}
                            <a href="{php echo createWebUrlPlugin('coupon.flag',array('themeid'=>$themeid,'used_type'=>$row['value']));}"
                               class="btn {if $used_type == $row['value']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                </div>
                {/if}
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">优惠券状态</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $user_flag_status_arr $row}
                            <a href="{php echo createWebUrlPlugin('coupon.flag',array('themeid'=>$themeid,'status'=>$row['value'],'coupon_id'=>$coupon_id));}"
                               class="btn {if $status == $row['value']}btn-primary{else}btn-default{/if}">
                                {$row['title']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-3 col-xs-3 col-md-3">
                        <input class="form-control" name="search_data" placeholder="输入用户昵称、姓名、手机号" type="text" value="{$_P['search_data']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>

                    <div class="col-sm-2 col-lg-2 col-md-2 col-xs-2">
                        {if $total<=5000}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出记录EXCEL">
                        {else}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出记录EXCEL(1-5000条)">
                        {/if}
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">昵称</th>
                        <th style="width: 120px">姓名/电话</th>

                        <th style="width: 120px">优惠券名称</th>
                        <th style="width: 100px">优惠券金额</th>
                        <th style="width: 100px">状态</th>
                        <th style="width: 100px">领取时间</th>
                        <th style="width: 100px">使用时间</th>
                        <th style="width: 120px">归属员工</th>
                        <th style="width: 120px;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $index $item}
                    <tr {if $item['order_id']==$record_id && $item['uid']==$uid && $item['status']==2}style="background:darkgray;"{/if}>
                        <td>{$item['id']}</td>
                        <td>
                            <a href="{php echo createWebUrlPlugin('coupon.flag',array('themeid'=>$themeid,'uid'=>$item['uid']));}">
                                {$item['nickname']}<br>
                                <img src="{php echo tomedia($item['avatar']);}" style="width: 28px;height: 28px;padding: 1px;">
                            </a>
                        </td>
                        <td>
                            {$item['username']}<br>
                            {$item['mobile']}
                        </td>

                        <td>{$item['name']}</td>
                        <td>{$item['price']}</td>
                        <td>
                            {if $item['status']==1}
                            <span class="label label-success">未使用</span>
                            {elseif $item['status']==2}
                            <span class="label label-danger">已使用</span>
                            {else}
                            <span class="label label-default">失效</span>
                            {/if}
                        </td>
                        <td>
                            {$item['created_at']}
                        </td>
                        <td>
                            {$item['updated_at']}
                        </td>
                        <td>{php echo $item['order_workername']?$item['order_workername']:$item['workername'];}</td>
                        <td>
                            {if $item['status']==2}
                            <a href="{php echo createWebUrl('record', array('themeid'=>$themeid,'keyword'=>$item['mobile']));}"  class="btn btn-primary"   title="查看订单" data-toggle="tooltip" data-placement="top">查看订单</a>
                            {else}
                            <a  class="btn btn-danger" onclick="deleteUserCoupon({$item['id']})"  title="删除" data-toggle="tooltip" data-placement="top">删除</a>
                            {/if}


                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

{$pager}
<script type="text/javascript">
    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }
    function jump(){
        layer.msg('正在准备下载');
    }
    //删除用户指定的优惠券
    function deleteUserCoupon(e) {
        let id = e;
        let postUrl = "{php echo createWebUrlPlugin('coupon.flag.delete',array('themeid'=>$themeid));}";
        layer.confirm('确定删除此用户优惠券？',{
            btn:['确定']
        },function () {
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data:{id:id},
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    if (status!=200){
                        layer.msg(result.msg)
                    }else{
                        layer.msg(result.msg);
                        window.location.reload();
                    }
                },
                fail:function (err) {
                    console.log(err)
                }
            })
        })

    }
</script>
